local toutao_skill = fk.CreateSkill {

  name = "#toutao_skill",

  tags = { Skill.Compulsory, },

}



toutao_skill:addEffect(fk.EventPhaseEnd, {
  attached_equip = "toutao",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(toutao_skill.name) and player.phase == Player.Judge
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judgeData = {
      who = player,
      reason = toutao_skill.name,
      pattern = ".|1~8|spade",
    }
    room:judge(judgeData)
    local toutao = Fk:getCardById(table.filter(player:getCardIds(Player.Equip), function(cid)
      return Fk:getCardById(cid).name == "toutao"
    end)[1])
    if judgeData.card.suit == Card.Spade and judgeData.card.number <= 8 then
      room:damage({
        to = player,
        card = judgeData.card,
        damage = 2,
      })
      room:moveCardTo(toutao, Card.PlayerHand, player, fk.ReasonJustMove, toutao_skill.name)
    end
  end,
})

return toutao_skill